#include "IsoCodeParser.h"

#include <QXmlStreamReader>
#include <QMap>

namespace Ipc2581b
{

IsoCodeParser::IsoCodeParser()
{

}

// TODO: investigate perf QMap vs QList vs QstringRef::toString()
bool IsoCodeParser::parse(QXmlStreamReader *reader, const QStringRef &data)
{
    static const QMap<QString, IsoCode> map =
    {
        {QStringLiteral("MW"), IsoCode::MW},
        {QStringLiteral("PE"), IsoCode::PE},
        {QStringLiteral("VA"), IsoCode::VA},
        {QStringLiteral("CH"), IsoCode::CH},
        {QStringLiteral("LU"), IsoCode::LU},
        {QStringLiteral("CA"), IsoCode::CA},
        {QStringLiteral("VN"), IsoCode::VN},
        {QStringLiteral("CZ"), IsoCode::CZ},
        {QStringLiteral("TW"), IsoCode::TW},
        {QStringLiteral("QA"), IsoCode::QA},
        {QStringLiteral("MS"), IsoCode::MS},
        {QStringLiteral("SR"), IsoCode::SR},
        {QStringLiteral("KM"), IsoCode::KM},
        {QStringLiteral("LV"), IsoCode::LV},
        {QStringLiteral("EE"), IsoCode::EE},
        {QStringLiteral("VU"), IsoCode::VU},
        {QStringLiteral("HR"), IsoCode::HR},
        {QStringLiteral("MO"), IsoCode::MO},
        {QStringLiteral("PN"), IsoCode::PN},
        {QStringLiteral("WS"), IsoCode::WS},
        {QStringLiteral("BB"), IsoCode::BB},
        {QStringLiteral("NF"), IsoCode::NF},
        {QStringLiteral("PY"), IsoCode::PY},
        {QStringLiteral("CN"), IsoCode::CN},
        {QStringLiteral("ER"), IsoCode::ER},
        {QStringLiteral("LB"), IsoCode::LB},
        {QStringLiteral("BD"), IsoCode::BD},
        {QStringLiteral("LS"), IsoCode::LS},
        {QStringLiteral("MU"), IsoCode::MU},
        {QStringLiteral("WF"), IsoCode::WF},
        {QStringLiteral("LR"), IsoCode::LR},
        {QStringLiteral("EH"), IsoCode::EH},
        {QStringLiteral("MQ"), IsoCode::MQ},
        {QStringLiteral("BJ"), IsoCode::BJ},
        {QStringLiteral("PF"), IsoCode::PF},
        {QStringLiteral("LT"), IsoCode::LT},
        {QStringLiteral("NI"), IsoCode::NI},
        {QStringLiteral("BY"), IsoCode::BY},
        {QStringLiteral("TP"), IsoCode::TP},
        {QStringLiteral("KR"), IsoCode::KR},
        {QStringLiteral("GU"), IsoCode::GU},
        {QStringLiteral("LC"), IsoCode::LC},
        {QStringLiteral("SO"), IsoCode::SO},
        {QStringLiteral("LY"), IsoCode::LY},
        {QStringLiteral("AZ"), IsoCode::AZ},
        {QStringLiteral("EC"), IsoCode::EC},
        {QStringLiteral("BW"), IsoCode::BW},
        {QStringLiteral("CC"), IsoCode::CC},
        {QStringLiteral("IQ"), IsoCode::IQ},
        {QStringLiteral("UA"), IsoCode::UA},
        {QStringLiteral("SJ"), IsoCode::SJ},
        {QStringLiteral("CY"), IsoCode::CY},
        {QStringLiteral("IS"), IsoCode::IS},
        {QStringLiteral("TH"), IsoCode::TH},
        {QStringLiteral("CG"), IsoCode::CG},
        {QStringLiteral("LI"), IsoCode::LI},
        {QStringLiteral("TM"), IsoCode::TM},
        {QStringLiteral("AU"), IsoCode::AU},
        {QStringLiteral("ST"), IsoCode::ST},
        {QStringLiteral("GY"), IsoCode::GY},
        {QStringLiteral("PL"), IsoCode::PL},
        {QStringLiteral("AE"), IsoCode::AE},
        {QStringLiteral("NZ"), IsoCode::NZ},
        {QStringLiteral("FK"), IsoCode::FK},
        {QStringLiteral("HU"), IsoCode::HU},
        {QStringLiteral("SV"), IsoCode::SV},
        {QStringLiteral("PM"), IsoCode::PM},
        {QStringLiteral("IE"), IsoCode::IE},
        {QStringLiteral("SM"), IsoCode::SM},
        {QStringLiteral("UM"), IsoCode::UM},
        {QStringLiteral("AR"), IsoCode::AR},
        {QStringLiteral("GL"), IsoCode::GL},
        {QStringLiteral("ML"), IsoCode::ML},
        {QStringLiteral("PH"), IsoCode::PH},
        {QStringLiteral("CI"), IsoCode::CI},
        {QStringLiteral("CF"), IsoCode::CF},
        {QStringLiteral("ES"), IsoCode::ES},
        {QStringLiteral("MD"), IsoCode::MD},
        {QStringLiteral("GP"), IsoCode::GP},
        {QStringLiteral("AD"), IsoCode::AD},
        {QStringLiteral("DM"), IsoCode::DM},
        {QStringLiteral("DE"), IsoCode::DE},
        {QStringLiteral("AW"), IsoCode::AW},
        {QStringLiteral("MA"), IsoCode::MA},
        {QStringLiteral("DK"), IsoCode::DK},
        {QStringLiteral("SG"), IsoCode::SG},
        {QStringLiteral("MM"), IsoCode::MM},
        {QStringLiteral("MR"), IsoCode::MR},
        {QStringLiteral("AT"), IsoCode::AT},
        {QStringLiteral("NU"), IsoCode::NU},
        {QStringLiteral("IT"), IsoCode::IT},
        {QStringLiteral("BT"), IsoCode::BT},
        {QStringLiteral("UG"), IsoCode::UG},
        {QStringLiteral("NE"), IsoCode::NE},
        {QStringLiteral("GE"), IsoCode::GE},
        {QStringLiteral("SZ"), IsoCode::SZ},
        {QStringLiteral("BE"), IsoCode::BE},
        {QStringLiteral("ZM"), IsoCode::ZM},
        {QStringLiteral("TO"), IsoCode::TO},
        {QStringLiteral("VE"), IsoCode::VE},
        {QStringLiteral("TJ"), IsoCode::TJ},
        {QStringLiteral("ET"), IsoCode::ET},
        {QStringLiteral("BA"), IsoCode::BA},
        {QStringLiteral("PK"), IsoCode::PK},
        {QStringLiteral("KI"), IsoCode::KI},
        {QStringLiteral("MN"), IsoCode::MN},
        {QStringLiteral("BH"), IsoCode::BH},
        {QStringLiteral("TF"), IsoCode::TF},
        {QStringLiteral("BZ"), IsoCode::BZ},
        {QStringLiteral("RE"), IsoCode::RE},
        {QStringLiteral("GF"), IsoCode::GF},
        {QStringLiteral("PA"), IsoCode::PA},
        {QStringLiteral("JO"), IsoCode::JO},
        {QStringLiteral("TT"), IsoCode::TT},
        {QStringLiteral("IR"), IsoCode::IR},
        {QStringLiteral("RW"), IsoCode::RW},
        {QStringLiteral("AF"), IsoCode::AF},
        {QStringLiteral("NG"), IsoCode::NG},
        {QStringLiteral("FO"), IsoCode::FO},
        {QStringLiteral("MV"), IsoCode::MV},
        {QStringLiteral("TC"), IsoCode::TC},
        {QStringLiteral("TN"), IsoCode::TN},
        {QStringLiteral("AN"), IsoCode::AN},
        {QStringLiteral("PT"), IsoCode::PT},
        {QStringLiteral("SB"), IsoCode::SB},
        {QStringLiteral("ZA"), IsoCode::ZA},
        {QStringLiteral("DZ"), IsoCode::DZ},
        {QStringLiteral("DO"), IsoCode::DO},
        {QStringLiteral("SA"), IsoCode::SA},
        {QStringLiteral("PW"), IsoCode::PW},
        {QStringLiteral("BV"), IsoCode::BV},
        {QStringLiteral("VC"), IsoCode::VC},
        {QStringLiteral("KY"), IsoCode::KY},
        {QStringLiteral("KN"), IsoCode::KN},
        {QStringLiteral("GN"), IsoCode::GN},
        {QStringLiteral("BG"), IsoCode::BG},
        {QStringLiteral("SI"), IsoCode::SI},
        {QStringLiteral("ZW"), IsoCode::ZW},
        {QStringLiteral("MP"), IsoCode::MP},
        {QStringLiteral("JP"), IsoCode::JP},
        {QStringLiteral("BI"), IsoCode::BI},
        {QStringLiteral("SN"), IsoCode::SN},
        {QStringLiteral("AS"), IsoCode::AS},
        {QStringLiteral("RO"), IsoCode::RO},
        {QStringLiteral("AG"), IsoCode::AG},
        {QStringLiteral("MY"), IsoCode::MY},
        {QStringLiteral("GW"), IsoCode::GW},
        {QStringLiteral("TV"), IsoCode::TV},
        {QStringLiteral("JM"), IsoCode::JM},
        {QStringLiteral("AQ"), IsoCode::AQ},
        {QStringLiteral("NP"), IsoCode::NP},
        {QStringLiteral("GH"), IsoCode::GH},
        {QStringLiteral("HN"), IsoCode::HN},
        {QStringLiteral("IN"), IsoCode::IN},
        {QStringLiteral("MT"), IsoCode::MT},
        {QStringLiteral("HK"), IsoCode::HK},
        {QStringLiteral("SL"), IsoCode::SL},
        {QStringLiteral("GB"), IsoCode::GB},
        {QStringLiteral("VI"), IsoCode::VI},
        {QStringLiteral("MH"), IsoCode::MH},
        {QStringLiteral("YU"), IsoCode::YU},
        {QStringLiteral("CO"), IsoCode::CO},
        {QStringLiteral("NO"), IsoCode::NO},
        {QStringLiteral("CL"), IsoCode::CL},
        {QStringLiteral("IL"), IsoCode::IL},
        {QStringLiteral("CK"), IsoCode::CK},
        {QStringLiteral("NR"), IsoCode::NR},
        {QStringLiteral("IO"), IsoCode::IO},
        {QStringLiteral("MC"), IsoCode::MC},
        {QStringLiteral("GM"), IsoCode::GM},
        {QStringLiteral("ZR"), IsoCode::ZR},
        {QStringLiteral("NA"), IsoCode::NA},
        {QStringLiteral("DJ"), IsoCode::DJ},
        {QStringLiteral("SC"), IsoCode::SC},
        {QStringLiteral("OM"), IsoCode::OM},
        {QStringLiteral("PR"), IsoCode::PR},
        {QStringLiteral("SK"), IsoCode::SK},
        {QStringLiteral("TK"), IsoCode::TK},
        {QStringLiteral("TZ"), IsoCode::TZ},
        {QStringLiteral("HM"), IsoCode::HM},
        {QStringLiteral("MK"), IsoCode::MK},
        {QStringLiteral("GQ"), IsoCode::GQ},
        {QStringLiteral("CU"), IsoCode::CU},
        {QStringLiteral("KZ"), IsoCode::KZ},
        {QStringLiteral("KE"), IsoCode::KE},
        {QStringLiteral("AO"), IsoCode::AO},
        {QStringLiteral("TG"), IsoCode::TG},
        {QStringLiteral("GR"), IsoCode::GR},
        {QStringLiteral("LK"), IsoCode::LK},
        {QStringLiteral("TD"), IsoCode::TD},
        {QStringLiteral("AI"), IsoCode::AI},
        {QStringLiteral("LA"), IsoCode::LA},
        {QStringLiteral("CV"), IsoCode::CV},
        {QStringLiteral("ID"), IsoCode::ID},
        {QStringLiteral("SD"), IsoCode::SD},
        {QStringLiteral("AL"), IsoCode::AL},
        {QStringLiteral("NC"), IsoCode::NC},
        {QStringLiteral("YE"), IsoCode::YE},
        {QStringLiteral("VG"), IsoCode::VG},
        {QStringLiteral("CX"), IsoCode::CX},
        {QStringLiteral("GS"), IsoCode::GS},
        {QStringLiteral("KP"), IsoCode::KP},
        {QStringLiteral("SH"), IsoCode::SH},
        {QStringLiteral("US"), IsoCode::US},
        {QStringLiteral("NL"), IsoCode::NL},
        {QStringLiteral("BR"), IsoCode::BR},
        {QStringLiteral("SE"), IsoCode::SE},
        {QStringLiteral("BN"), IsoCode::BN},
        {QStringLiteral("CR"), IsoCode::CR},
        {QStringLiteral("BM"), IsoCode::BM},
        {QStringLiteral("TR"), IsoCode::TR},
        {QStringLiteral("EG"), IsoCode::EG},
        {QStringLiteral("CM"), IsoCode::CM},
        {QStringLiteral("AM"), IsoCode::AM},
        {QStringLiteral("UZ"), IsoCode::UZ},
        {QStringLiteral("SY"), IsoCode::SY},
        {QStringLiteral("GI"), IsoCode::GI},
        {QStringLiteral("KH"), IsoCode::KH},
        {QStringLiteral("MG"), IsoCode::MG},
        {QStringLiteral("GT"), IsoCode::GT},
        {QStringLiteral("FR"), IsoCode::FR},
        {QStringLiteral("BS"), IsoCode::BS},
        {QStringLiteral("RU"), IsoCode::RU},
        {QStringLiteral("UY"), IsoCode::UY},
        {QStringLiteral("FX"), IsoCode::FX},
        {QStringLiteral("BO"), IsoCode::BO},
        {QStringLiteral("BF"), IsoCode::BF},
        {QStringLiteral("FI"), IsoCode::FI},
        {QStringLiteral("HT"), IsoCode::HT},
        {QStringLiteral("MX"), IsoCode::MX},
        {QStringLiteral("KG"), IsoCode::KG},
        {QStringLiteral("KW"), IsoCode::KW},
        {QStringLiteral("FJ"), IsoCode::FJ},
        {QStringLiteral("YT"), IsoCode::YT},
        {QStringLiteral("PG"), IsoCode::PG},
        {QStringLiteral("GA"), IsoCode::GA},
        {QStringLiteral("GD"), IsoCode::GD},
        {QStringLiteral("FM"), IsoCode::FM},
        {QStringLiteral("MZ"), IsoCode::MZ},
    };
    if (!map.contains(data.toString()))
    {
        reader->raiseError(QStringLiteral("\"%1\": invalid value for enum IsoCode").arg(data.toString()));
        return false;
    }
    m_result = map.value(data.toString());
    return true;
}

IsoCode IsoCodeParser::result()
{
    return m_result;
}

}